﻿using System;
using System.Text;
using System.Runtime.InteropServices;

namespace RaisingStudio.SmallProgram.Library.Internal
{
    internal static class NativeHelper
    {
        public const int GWL_STYLE = -16;
        public const int SPI_SETDESKWALLPAPER = 20;
        public const int SPIF_SENDWININICHANGE = 2;
        public const int SPIF_UPDATEINIFILE = 1;
        public const int STD_ERROR_HANDLE = -12;
        public const int STD_INPUT_HANDLE = -10;
        public const int STD_OUTPUT_HANDLE = -11;
        public const int SWP_NOSIZE = 1;
        public const uint WS_CAPTION = 0xc00000;
        public const uint WS_MAXIMIZEBOX = 0x10000;
        public const uint WS_MINIMIZEBOX = 0x20000;

        [DllImport("user32.dll")]
        public static extern bool AdjustWindowRect(ref RECT lpRect, uint dwStyle, bool bMenu);
        [DllImport("kernel32")]
        public static extern bool AllocConsole();
        [DllImport("kernel32.dll")]
        public static extern bool FreeConsole();
        [DllImport("kernel32.dll")]
        public static extern uint GetConsoleTitle([Out] StringBuilder lpConsoleTitle, uint nSize);
        [DllImport("kernel32.dll")]
        public static extern IntPtr GetConsoleWindow();
        [DllImport("kernel32.dll")]
        public static extern IntPtr GetStdHandle(int nStdHandle);
        [DllImport("user32.dll")]
        public static extern uint GetWindowLong(IntPtr hWnd, int nIndex);
        [DllImport("user32.dll")]
        public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
        [DllImport("winmm.dll")]
        public static extern int midiOutOpen(ref int midiOut, int uDeviceID, int dwCallback, int dwCallbackInstance, uint dwFlags);
        [DllImport("winmm.dll")]
        public static extern int midiOutShortMsg(int midiOut, uint dwMsg);
        [DllImport("kernel32.dll")]
        public static extern bool SetConsoleTextAttribute(IntPtr hConsoleOutput, ushort wAttributes);
        [DllImport("kernel32.dll")]
        public static extern bool SetConsoleTitle(string lpConsoleTitle);
        [DllImport("user32.dll")]
        public static extern bool SetForegroundWindow(IntPtr hWnd);
        [DllImport("user32.dll")]
        public static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);
        [DllImport("user32.dll")]
        public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
    }
}

